package com.xiaoyu.im.client.proxy.nim;

import com.netease.nimlib.sdk.msg.attachment.MsgAttachment;
import com.netease.nimlib.sdk.msg.attachment.MsgAttachmentParser;

import org.jetbrains.annotations.NotNull;

import in.srain.cube.request.JsonData;

public class CustomAttachment implements MsgAttachment {

    private final String mJson;

    public static CustomAttachment fromJsonData(JsonData jsonData) {
        return new CustomAttachment(jsonData.toString());
    }

    public static CustomAttachment fromJson(String json) {
        return new CustomAttachment(json);
    }

    private CustomAttachment(String json) {
        this.mJson = json;
    }

    public JsonData toJsonData() {
        return JsonData.create(mJson);
    }

    @Override
    public String toJson(boolean send) {
        return mJson;
    }

    @NotNull
    @Override
    public String toString() {
        return mJson;
    }

    public static class CustomAttachParser implements MsgAttachmentParser {

        @Override
        public MsgAttachment parse(String json) {
            return CustomAttachment.fromJson(json);
        }
    }
}
